K.define('kuser.charment',{
   kpartname:'统计图表信息',//模块名称
   gridid:"dlrzechar_gridlist",//表格列表id
   echar:"dlrzechar_echar",//表格列表id
   addwin:"dlrzechar_addwin",//添加弹出win id
   updwim:"dlrzechar_updatewin",//修改弹出win id
   editFlag:undefined,
   /**
    * 初始化
    * @param me
    * @param type
    */
   init: function (me,type) {
		me.kuser_gridlist(me,"1","1","1");
		me.onchangeradio(me);
		me.onchangekmtype(me);
		me.onchangetype(me);
	},
	/**
	 * 渲染表格
	 * @param me
	 */
   kuser_gridlist:function(me,ktjtype,kmtype,kechartype){
	   var kdoms=$("#dlrzechar_echar",me.contentTarget).get(0);
	   $('#dlrzechar_echar',$(me.contentTarget)).css("width", K.getwinwidth(300));
	   $('#dlrzechar_echar',$(me.contentTarget)).css("height", K.getwinheight(200));
	   var startime=$('#ksrq',$(me.contentTarget)).val();
	   var endtime=$('#jsrq',$(me.contentTarget)).val();
	   $.ajax({
		    async:false,//是否异步
		    cache:false,//是否使用缓存
		    type:'POST',//请求方式：post
		    dataType:'json',//数据传输格式：json
		    url:"chars/kcharcount",//请求的action路径
		    data:{"ktjtype":ktjtype,"ktype":kmtype,"kssj":startime,"jssj":endtime},
		    error:function(){
		      alert('亲，请求失败！');
		    },
		    success:function(data){
		    	if(kechartype=="1"){
		    		me.columnchar(me,data);
		    	}else{
		    		me.piechar(me,data);
		    	}
		    }
		  });
	  },
onchangeradio:function(me){
 $("input[name='ktjtype']",$(me.contentTarget)).click(function(el){
	 var ktjtype = $(this).val();
     me.selectkuser(me,"1");
	});	
},	
onchangekmtype:function(me){
	 $("input[name='kmtype']",$(me.contentTarget)).click(function(el){
		 var ktjtype = $(this).val();
	     me.selectkuser(me,"1");
		});	
	},
onchangetype:function(me){
	 $("input[name='kechartype']",$(me.contentTarget)).click(function(el){
		 var ktjtype = $(this).val();
	     me.selectkuser(me,"1");
		});	
	},
columnchar:function(me,data){
	    var myChart = echarts.init(document.getElementById('dlrzechar_echar'));
	    var option = {
	            title: {
	                text: '统计图表'
	                //subtext: '纯属虚构'
	            },
	           tooltip: {},
	           toolbox: {
               show: true,
               feature: {
                   magicType: { show: true, type: ['line', 'bar'] },
                   saveAsImage: { show: true }
               }
              },
	          legend: {
	                data:data.legend
	            },
	            xAxis: {
	            	data: data.xAxis
	            },
	            yAxis: {
	            	  type : 'value'
	            },
	            series:data.series
	        };
	     myChart.on('click', function (params) {
	    	 //console.log(params);
         });
	     myChart.setOption(option,true);
},
piechar:function(me,data){
	var myChart = echarts.init(document.getElementById('dlrzechar_echar'));
	var option = {
		    title : {
		        text: '统计图表',
		        //subtext: '纯属虚构',
		        x:'center'
		    },
		    tooltip : {
		        trigger: 'item',
		        formatter: "{a} <br/>{b} : {c} ({d}%)"
		    },
		    legend: {
		        orient : 'vertical',
		        x : 'left',
		        data:data.xAxis
		    },
		    toolbox: {
		        show : true,
		        feature : {
		            //mark : {show: true},
		            //dataView : {show: true, readOnly: false},
		            magicType : {
		                show: true, 
		                type: ['pie', 'funnel'],
		                option: {
		                    funnel: {
		                        x: '25%',
		                        width: '50%',
		                        funnelAlign: 'left',
		                        max: 1548
		                    }
		                }
		            },
		            restore : {show: true},
		            saveAsImage : {show: true}
		        }
		    },
		    calculable : true,
		    series : [{
		            name:'登录次数',
		            type:'pie',
		            radius : '55%',
		            center: ['50%', '60%'],
		            data:data.datalist
		        }]
		};
	 myChart.setOption(option,true);
},
	  /**
	   * 查询
	   * @param me
	   * @param formid
	   */
	  selectkuser:function(me,ktype){
		 var ktjtype = $("input[name='ktjtype']:checked",$(me.contentTarget)).val();
		 var kmtype = $("input[name='kmtype']:checked",$(me.contentTarget)).val();
		 var kechartype = $("input[name='kechartype']:checked",$(me.contentTarget)).val();
		 me.kuser_gridlist(me,ktjtype,kmtype,kechartype);
	},
	onwinsize:function(){
		 $(".window").css("z-index","1001");
         $(".window-shadow").css("z-index","900");
         $(".window-mask").css("z-index","900");
	}
}, true);